﻿@using System.Text
@using JuCheap.Service.Dto
@using JuCheap.Service.Enum
@model MenuDto
@{
    ViewBag.Title = "Add";
    Layout = "~/Areas/Adm/Views/Shared/_Layout_Body.cshtml";
    List<MenuDto> parentMenus = ViewBag.ParentMenu;
}
@section StylesBefore{
    @Styles.Render("~/Template/Admin/jucheap/Css/SelectStyle")
}

@section Scripts{
    @Scripts.Render("~/JS/Admin/jucheap/Select")
    <script>
        $("#submitForm").validate({
            submitHandler: jucheap.buttonLoading,
            rules: {
                Name: {
                    required: true,
                    minlength: 2,
                    maxlength: 20
                },
                Url: {
                    required: true,
                    minlength: 1,
                    maxlength: 300
                }
            },
            messages: {
                Name: {
                    required: "请输入菜单名称",
                    minlength: "最小长度为2个字符",
                    maxlength: "最大长度为20个字符"
                },
                Url: {
                    required: "请输入UEL地址，没有地址，请用#代替",
                    minlength: "最小长度为1个字符",
                    maxlength: "最大长度300个字符"
                }
            }
        });
    </script>
}

<div class="row">
    <div class="col-lg-12">
        <section class="panel">
            <header class="panel-heading">
                添加菜单
            </header>
            <div class="panel-body">
                <div class="form">
                    <form class="cmxform form-horizontal tasi-form" id="submitForm" method="POST" action="@Request.Url.PathAndQuery" novalidate="novalidate">
                        @Html.HiddenFor(item => item.Id, new { @class = "form-control" })


                        <div class="form-group ">
                            @Html.LabelFor(item => item.ParentId, new {@class = "control-label col-lg-2"})
                            <div class="col-lg-10">
                                <select class="form-control select2" id="ParentId" name="ParentId">
                                    <option value=""></option>
                                    @if (parentMenus != null && parentMenus.Any())
                                    {
                                        StringBuilder sb = new StringBuilder();
                                        var moudles = parentMenus.Where(item => item.Type == MenuType.模块).ToList();
                                        sb.Append("<optgroup label=\"顶级\">");
                                        sb.AppendFormat("<option value=\"{0}\">{1}</option>", 0, "顶级");
                                        sb.Append("</optgroup>");
                                        sb.Append("<optgroup label=\"模块\">");
                                        foreach (var m in moudles)
                                        {

                                            sb.AppendFormat("<option value=\"{0}\">{1}</option>", m.Id, m.Name);

                                        }
                                        sb.Append("</optgroup>");

                                        var menus = parentMenus.Where(item => item.Type == MenuType.菜单).ToList();
                                        sb.Append("<optgroup label=\"菜单\">");
                                        foreach (var m in menus)
                                        {

                                            sb.AppendFormat("<option value=\"{0}\">{1}</option>", m.Id, m.Name);

                                        }
                                        sb.Append("</optgroup>");

                                        @(new MvcHtmlString(sb.ToString()))
                                    }
                                </select>
                            </div>
                        </div>

                        <div class="form-group ">
                            @Html.LabelFor(item => item.Name, new {@class = "control-label col-lg-2"})
                            <div class="col-lg-10">
                                @Html.TextBoxFor(item => item.Name, new {@class = "form-control"})
                            </div>
                        </div>

                        <div class="form-group ">
                            @Html.LabelFor(item => item.Url, new { @class = "control-label col-lg-2" })
                            <div class="col-lg-10">
                                @Html.TextBoxFor(item => item.Url, new { @class = "form-control" })
                            </div>
                        </div>

                        <div class="form-group ">
                            @Html.LabelFor(item => item.Order, new { @class = "control-label col-lg-2" })
                            <div class="col-lg-10">
                                @Html.TextBoxFor(item => item.Order, new { @class = "form-control" })
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-lg-offset-2 col-lg-10">
                                <button class="btn btn-success" type="submit">保存</button>
                                <button class="btn btn-default" type="button" onclick="jucheap.goback(this)">返回</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </section>
    </div>
</div>




